<template>
	<view class="change_password_main">
		<view class="account_info">
			<view class="account_info_title">
				原密码
			</view>
			<view class="account_info_input">
				<input type="text" value="" v-model="oldPassword" placeholder-style="font-size:14px;color:#999999;" placeholder="请输入原密码" />
			</view>
		</view>
		<view class="account_info">
			<view class="account_info_title">
				新密码
			</view>
			<view class="account_info_input">
				<input type="text" value="" v-model="newPassword" placeholder-style="font-size:14px;color:#999999;" placeholder="请输入新密码" />
			</view>
		</view>
		<view class="account_info">
			<view class="account_info_title">
				确认密码
			</view>
			<view class="account_info_input">
				<input type="text" value="" v-model="againPassword" placeholder-style="font-size:14px;color:#999999;" placeholder="请再次输入新密码" />
			</view>
		</view>
		<view class="register_btn btns" @click="submit()">
			确定
		</view>
	</view>
</template>

<script>
	import { isvalidPassword } from '../../../utils/validate.js'
	export default {
		data() {
			return {
				/** 旧密码 */
				oldPassword: '',
				/** 新密码 */
				newPassword: '',
				/** 确认密码 */
				againPassword: '',
			}
		},
		
		onLoad() {
		},
		
		components: { 
		},
		
		methods: {
			/** 找回密码 */
			submit() {
				/** 原密码 */
				if (!this.oldPassword) {
					uni.showToast({
						title: '请输入原密码',
						icon: 'none',
						duration: 3000,
						position: 'bottom'
					});
					return
				}
				/** 新密码 */
				if (!isvalidPassword(this.newPassword)) {
					uni.showToast({
						title: '请输入(6-16)位由数字和字母组成的新密码',
						icon: 'none',
						duration: 3000,
						position: 'bottom'
					});
					return
				}
				/** 确认密码 */
				if (!this.againPassword) {
					uni.showToast({
						title: '请再次确认密码',
						icon: 'none',
						duration: 3000,
						position: 'bottom'
					});
					return
				}
				/** 判断两次密码是否一致 */
				if (this.newPassword !== this.againPassword) {
					uni.showToast({
						title: '两次输入密码不一致',
						icon: 'none',
						duration: 3000,
						position: 'bottom'
					});
					return
				}
				let parameter = {
					password: this.oldPassword, // 原密码
					new_password: this.newPassword, // 新密码
					af_password: this.againPassword // 再次确认密码
				}
				this.$post(this.api.updatePassword, parameter, 'post', { token: uni.getStorageSync('token') }).then((res) => {
					console.log(res)
					/** 关闭当前页，返回至登录页 */
					uni.navigateTo({
						url: '../login/index'
					})
				}).catch((err) => {
					console.log(err)
				})
			}
		},
	}
</script>

<style lang="less" scoped>
	@import "@/asset/less/base.less";
	.change_password_main {
		padding: 68rpx 60rpx 0 60rpx;
		.account_info {
			padding-bottom: 60rpx;
			.account_info_title {
				font-size: 36rpx;
				color: #1A1A1A;
				padding-bottom: 30rpx;
			}
			.account_info_input {
				font-size: 28rpx;
				padding-bottom: 15rpx;
				color: #999;
				border-bottom: 1px solid #F3f3f3;
			}
		}
		.register_btn {
			margin-top: 30rpx;
		}
	}
</style>
